package net.anzhuo.service.impl;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.dao.GsCertificatesMapper;
import net.anzhuo.entity.GsCertificates;
import net.anzhuo.service.GsCertificatesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GsCertificatesServiceImpl implements GsCertificatesService {

	@Autowired
	private GsCertificatesMapper gsCertificatesMapper;

	@Override
	public PaginationVO<GsCertificates> getListWithPage(GsCertificates gsCertificates) {
		PaginationVO<GsCertificates> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsCertificatesMapper.getListWithPage(gsCertificates));
		paginationVO.setTotalCount(gsCertificatesMapper.getCount(gsCertificates));
		paginationVO.setTotalPage((gsCertificatesMapper.getCount(gsCertificates) + gsCertificates.getPageSize() -1)  / gsCertificates.getPageSize());
		paginationVO.setPageNo(gsCertificates.getPageNo());
		return paginationVO;
	}

	@Override
	public GsCertificates getById(Long id) {
		return gsCertificatesMapper.getById(id);
	}

	@Override
	public List<GsCertificates> getList() {
		return gsCertificatesMapper.getList();
	}

	@Override
	public List<GsCertificates> getList(GsCertificates gsCertificates) {
		return gsCertificatesMapper.getListByQuery(gsCertificates);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsCertificates gsCertificates) {
		gsCertificatesMapper.update(gsCertificates);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsCertificates gsCertificates) {
		gsCertificatesMapper.save(gsCertificates);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(GsCertificates gsCertificates) {
		gsCertificatesMapper.delete(gsCertificates);
	}

	@Override
	public List<GsCertificates> getByMd5(String md5) {
		return gsCertificatesMapper.getByMd5(md5);
	}
}
